<?php
//add joke
if(isset($_POST['hidd']) and $_POST['hidd'] == 'ok' and $_POST['joke'] ){
	$result = Joke::addJoke($_POST['joke'],$user);
	Info::setInfo("Joke send");
}

//add user
if (isset($_POST['hidden']) and $_POST['hidden']=='add_user'){
	if (
		isset($_POST['user_login'])
		and isset($_POST['user_password'])
		and $_POST['user_password']!= "" 
		and $_POST['user_login']!=""
		and $_POST['user_password'] == $_POST['user_password2']
		and $_POST['email'] != ""
		){
			if(strlen($_POST['user_password'])>=5){
				if(User::check_email($_POST['email'])){	
					if(User::add_user($_POST['user_login'],$_POST['user_password'],$_POST['email'])){
						Info::setInfo("Now you can connect with your login/password");
					}else{
						$errorstring="User already exist";
					}
				}else{
					$errorstring="Invalid email";							
				}
			}else{
				$errorstring="To short password";
			}
	}
	else{
		$errorstring="Name/Password/Email missing or wrong";
	}
	Info::setError($errorstring);
	header("Location: index.php?page=register");
	exit();
}

//login user
if (isset($_POST['hidden']) and $_POST['hidden']=='login'){
	if(! $user->check_password($_POST['user_login'],$_POST['user_password']) ){
		Info::setError("Login/Password invalid");
		header("Location: index.php?page=login");
		exit();	
	}
}

//disconnect user
if (isset($_GET['action'])){
	if($_GET['action']=="disconnect"){
		$user->disconnect_user();
		$user = NULL;
	}
}
//rss
if($_GET['page']=="rss"){
			include("rss.php");
			exit();
	}

?>
